<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"

      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>JSF2 Teste</title>
    </h:head>
    <h:body>
        <center>
            <h:form id="formA">
                Cadastro de Pessoas<br/>
                <p:panelGrid columns="2">
                    Nome:<p:inputText id="nomeTxt" value="#{pessoaBean.pessoa.nome}"/>
                    Email:<p:inputText id="emailTxt" value="#{pessoaBean.pessoa.email}"/>
                    Telefone:<p:inputText id="telefoneTxt" value="#{pessoaBean.pessoa.telefone}"/>
                    <h:inputHidden/>
                    <p:commandButton value="Cadastrar" actionListener="#{pessoaBean.adicionarPessoa}" update="@all"  />
                </p:panelGrid>
            </h:form>
            <br/>
            <p:dataTable value="#{pessoaBean.listarPessoa()}" var="data" rows="10" paginator="true" id="table">
                <p:column>
                    <f:facet name="header">
                        NOME
                    </f:facet>
                    <h:outputText value="#{data.nome}"/>
                </p:column>
                <p:column>
                    <f:facet name="header">
                        EMAIL
                    </f:facet>
                    <h:outputText value="#{data.email}"/>
                </p:column>
                <p:column>
                    <f:facet name="header">
                        TELEFONE
                    </f:facet>
                    <h:outputText value="#{data.telefone}"/>
                </p:column>
                <p:column>
                    <f:facet name="header">
                        AÇÕES
                    </f:facet>
                    <h:form>
                        <p:growl id="message" showDetail="true" />
                        <p:commandButton value="Remover" actionListener="#{pessoaBean.removerPessoa(data)}" update=":table" >
                            <p:confirm header="Confirmation" message="Tem certeza que deseja remover este registro?" icon="ui-icon-alert" />
                        </p:commandButton>
                        <p:confirmDialog global="true" showEffect="fade" hideEffect="explode">
                            <p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
                            <p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />   

                        </p:confirmDialog>

                        |
                        <p:commandButton value="Editar" action="#{pessoaBean.carregarPessoa(data)}"/>
                    </h:form>
                </p:column>
            </p:dataTable>


        </center>
    </h:body>
</html>

